import { defineStore } from 'pinia'

export const appCurrentState = defineStore('currentState', {
  persist: { // 自定义持久化方式
    storage: window.sessionStorage,
    beforeRestore: context => {
      console.log('Before', context)
    },
    afterRestore: context => {
      console.log('After', context)
    }
  },
  state: () => {
    return {
      // 当前详情id
      currentDetailId: '',
      // 当前状态是否是编辑
      isEdit: true,
      // 当前选择的对象数据
      currentDetailInfo: '',
      // 页面类型
      type:'',
      // 当前消息
      currentMsg:[]
    }
  },

  actions: {
    SET_CURRENT_ID(id) {
      this.currentDetailId = id
    },
    SET_CURRENT_STATE(editState) {
      this.isEdit = editState
    },
    SET_CURRENT_ITEM(item) {
      this.currentDetailInfo = item
    },
    SET_CURRENT_TYPE(item) {
      this.type = item
    },
    SET_MSG(arr){
      this.currentMsg = arr
    }
  },

  getters: {
    getCurrentDetailId: state => state.currentDetailId,
    getCurrentDetailInfo: state => state.currentDetailInfo,
    getCurrentStatus: state => state.isEdit,
    getCurrentType: state => state.type,
    getMsg: state => state.currentMsg,
  }
})
